package code4;

import java.util.List;
import java.util.Scanner;

// 删除学生信息
public class Code3 {

    public void remove(List<Student> list){

        System.out.println("请输入要删除的学生的学号或姓名：");
        Scanner input = new Scanner(System.in);
        String str = input.next();
        if(str.charAt(0)>='0' && str.charAt(0)<='9'){
            long l = Long.parseLong(str);
            remove2(list, l);
        }else{
            remove1(list, str);
        }
    }

    public void remove1(List<Student> list, String s){

        for(int i=0; i<list.size(); i++){
            if(s.equals(list.get(i).getName())){
                list.remove(i);
                return;
            }
        }
        System.out.println("没有这位学生！");
    }

    public void remove2(List<Student> list, long l){

        for(int i=0; i<list.size(); i++){
            if(l == (list.get(i).getId())){
                list.remove(i);
                return;
            }
        }
        System.out.println("没有这位学生！");
    }

}
